package com.diamond.smart.info.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.diamond.smart.info.entity.RegionEntity;
import com.diamond.smart.info.service.RegionService;
import com.diamond.common.utils.PageUtils;
import com.diamond.common.utils.R;


/**
 * @author SunKewei
 * @email skw777jo@163.com
 * @date 2022-04-26 16:02:20
 */
@RestController
@RequestMapping("info/region")
public class RegionController {
    @Autowired
    private RegionService regionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = regionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{regionId}")
    public R info(@PathVariable("regionId") Long regionId) {
        RegionEntity region = regionService.getById(regionId);

        return R.ok().put("region", region);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RegionEntity region) {
        regionService.save(region);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RegionEntity region) {
        regionService.updateById(region);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] regionIds) {
        regionService.removeByIds(Arrays.asList(regionIds));

        return R.ok();
    }

}
